package com.ebpm.designer.line
{
	import com.ebpm.designer.WF;
	import com.ebpm.designer.WP;
	import com.ebpm.designer.WorkPanel;
	import com.ebpm.designer.dir.LineEndDir;
	import com.ebpm.designer.dir.LineFromDir;

	//向下，向右的箭头
	public class DLLine extends Line
	{
		public function DLLine()
		{
			this.resizeFromDir = new LineFromDir(this, "leftRightIcon");
			this.resizeToDir = new LineEndDir(this, "upDownIcon");
			this.lineHeadType = "right";
			super();
		}
		
		override protected function initPoints(fromX:Number, fromY:Number, x:Number, y:Number):void {
			var itemSize:Number = WF.ITEM_SIZE;
			var p1:Point = new Point(fromX + (itemSize / 2) + this.resizeFromExtraX, y + (itemSize / 2) + this.resizeToExtraY);
			this.points.addItem(p1);
		}
		
		override public function repaintLine(type:String = "to"):void {
			var fromX:Number = this.sourceItem.nodeContainer.getDownLineX();
			var fromY:Number = this.sourceItem.nodeContainer.getDownLineY();
			var toX:Number = this.targetItem.nodeContainer.getLeftLineX();
			var toY:Number = this.targetItem.nodeContainer.getLeftLineY();
			
			if(this.endPoint.x - WF.LINE_HEAD_W <= (this.points.getItemAt(1) as Point).x) {
				WF.wp.removeElement(this);
				this.sourceItem.sourceLines.removeItem(this);
				this.targetItem.targetLines.removeItem(this);
				var line:Line = new DTLine().paint(fromX, fromY, this.targetItem.nodeContainer.getTopLineX(), this.targetItem.nodeContainer.getTopLineY());
				this.sourceItem.sourceLines.addItem(line);
				this.targetItem.nodeContainer.topItem.targetLines.addItem(line);
				line.sourceItem = this.sourceItem;
				line.targetItem = this.targetItem.nodeContainer.topItem;
			}
			else if(this.endPoint.y - this.startPoint.y <= WF.LINE_HEAD_H) {
				WF.wp.removeElement(this);
				this.sourceItem.sourceLines.removeItem(this);
				this.targetItem.targetLines.removeItem(this);
				var line:Line = new DDLine().paint(fromX, fromY, this.targetItem.nodeContainer.getDownLineX(), this.targetItem.nodeContainer.getDownLineY());
				this.sourceItem.sourceLines.addItem(line);
				this.targetItem.nodeContainer.downItem.targetLines.addItem(line);
				line.sourceItem = this.sourceItem;
				line.targetItem = this.targetItem.nodeContainer.downItem;
			}
			else {
				this.points.removeAll();
				this.startPoint = null;
				this.endPoint = null;
				paint(fromX, fromY, toX, toY);
			}
		}
		
		//拖拽框移动
		override public function resizeFromItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeFromExtraX;
				this.isFirstMove = false;
			}
			this.resizeFromExtraX = this.resizeStartExtra + WP.mouseChangeX;
			this.points.removeAll();
			var fromX = this.sourceItem.nodeContainer.getDownLineX();
			var fromY = this.sourceItem.nodeContainer.getDownLineY();
			var toX = this.targetItem.nodeContainer.getLeftLineX();
			var toY = this.targetItem.nodeContainer.getLeftLineY();
			this.paint(fromX, fromY, toX, toY);
		}

		
		override public function resizeEndItem():void {
			if(this.isFirstMove) {
				this.resizeStartExtra = this.resizeToExtraY;
				this.isFirstMove = false;
			}
			this.resizeToExtraY = this.resizeStartExtra + WP.mouseChangeY;
			this.points.removeAll();
			var fromX = this.sourceItem.nodeContainer.getDownLineX();
			var fromY = this.sourceItem.nodeContainer.getDownLineY();
			var toX = this.targetItem.nodeContainer.getLeftLineX();
			var toY = this.targetItem.nodeContainer.getLeftLineY();
			this.paint(fromX, fromY, toX, toY);
			this.movingTxtByLine();
		}
		
		
		
		
		
		
		
		
		
		
	}
}